package model;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * Created with IntelliJ IDEA.
 * User: Алексей
 * Date: 31.05.14
 * Time: 21:44
 * To change this template use File | Settings | File Templates.
 */
public class Connector {
    private static Connection conn = null;

    public static Connection getConnection() {
        if (conn == null) {
            try {
                Class.forName("com.mysql.jdbc.Driver");
                conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tskmanager", "root", "root123");
                System.out.println("Open connection " + conn.toString());
            } catch (Exception e) {
                System.out.println(e.getMessage());
                e.printStackTrace();
            }
        }
        System.out.println("Get connection " + conn.toString());
        return conn;
    }


    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        System.out.println("Close connection " + conn.toString());
        conn.close();

        //To change body of overridden methods use File | Settings | File Templates.
    }
}
